package com.example.deploysinggle.test1.common.util;

import com.example.deploysinggle.test1.common.enums.CommonResponseCodeEnum;
import com.example.deploysinggle.test1.common.enums.ErrorEnum;
import com.example.deploysinggle.test1.common.exeptions.BizException;
import com.example.deploysinggle.test1.common.resp.CommonErrorInfo;
import com.example.deploysinggle.test1.common.resp.CommonResponse;
import com.example.deploysinggle.test1.common.resp.CommonSingleResponse;

import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/1/23 16:57
 */
public class ResponseUtil {

    public  static  <T> CommonSingleResponse<T> success(T data){
        CommonSingleResponse <T> resp = new CommonSingleResponse<>();
        resp.setData(data);
        resp.setCode(CommonResponseCodeEnum.ALL_SUCCESS.getCode());
        return resp;
    }

    public  static  <T> CommonResponse<T> success(List<T> data){
        CommonResponse <T> resp = new CommonResponse<>();
        resp.setData(data);
        resp.setCode(CommonResponseCodeEnum.ALL_SUCCESS.getCode());
        return resp;
    }

    public  static  <T> CommonSingleResponse<T> partlyFail(T data){
        CommonSingleResponse <T> resp = new CommonSingleResponse<>();
        resp.setData(data);
        resp.setCode(CommonResponseCodeEnum.PARTLY_FAIL.getCode());
        resp.setErrorInfo(CommonErrorInfo.builder()
        .errCode(ErrorEnum.SYSTEM_ERROR.getCode())
        .errMessage(ErrorEnum.SYSTEM_ERROR.getDesc())
        .build());
        return resp;
    }

    public  static  <T> CommonResponse<T> partlyFail(List<T> data){
        CommonResponse <T> resp = new CommonResponse<>();
        resp.setData(data);
        resp.setCode(CommonResponseCodeEnum.PARTLY_FAIL.getCode());
        resp.setErrorInfo(CommonErrorInfo.builder()
                .errCode(ErrorEnum.SYSTEM_ERROR.getCode())
                .errMessage(ErrorEnum.SYSTEM_ERROR.getDesc())
                .build());
        return resp;
    }

    public  static  <T> CommonSingleResponse<T> partlyFail(T data, BizException exception){
        CommonSingleResponse <T> resp = new CommonSingleResponse<>();
        resp.setData(data);
        resp.setCode(CommonResponseCodeEnum.PARTLY_FAIL.getCode());
        resp.setErrorInfo(CommonErrorInfo.builder()
                .errCode(ErrorEnum.SYSTEM_ERROR.getCode())
                .errMessage(ErrorEnum.SYSTEM_ERROR.getDesc())
                .build());
        return resp;
    }

    public  static  <T> CommonSingleResponse<T> allFail(Exception exception){
        CommonSingleResponse <T> resp = new CommonSingleResponse<>();
        resp.setCode(CommonResponseCodeEnum.PARTLY_FAIL.getCode());
        resp.setErrorInfo(CommonErrorInfo.builder()
                .errCode(ErrorEnum.SYSTEM_ERROR.getCode())
                .errMessage(ErrorEnum.SYSTEM_ERROR.getDesc())
                .build());
        return resp;
    }

    public  static  <T> CommonSingleResponse<T> allFail(BizException exception){
        CommonSingleResponse <T> resp = new CommonSingleResponse<>();
        resp.setCode(CommonResponseCodeEnum.PARTLY_FAIL.getCode());
        resp.setErrorInfo(CommonErrorInfo.builder()
                .errCode(exception.getErrorEnum().getCode())
                .errMessage(exception.getErrorEnum().getDesc())
                .build());
        return resp;
    }
}
